const baseURL = "http://47.94.6.186:3001"

function request(option) {
  const { url, data = {}, method = "GET", header = {} } = option;
  method.toUpperCase();
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseURL + url,
      header: {
        "Content-type": "application/json",
      },
      method,
      data,
      success: (res) => {
        return resolve(res.data);
      },
      fail: (err) => {
        return reject(err); 
      }
    })
  })
}

const get = (url, data = {}) => request({ url, data, method: "GET" });
const post = (url, data = {}) => request({ url, data, method: "POST" });

module.exports = {
  get,
  post
}